//
//  SJDLookDetailVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/12.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "SJDLookDetailVC.h"
#import "SYRequestAPI+Teach.h"
@implementation SJDLookDetailVC

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame andPaperFilePath:(NSString *)path{
    if ([super initWithFrame:frame]) {
        self.path = path;
        [self initSubView];
        [self getShiJuanDetailRequest];
    }
    return self;
}
- (void)initSubView{
    self.backgroundColor = MAINBACKCOLOR;
    [self addSubview:self.backButton];
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@10);
        make.width.equalTo(@50);
        make.height.equalTo(@20);
    }];
    [self addSubview:self.mainImageView];
    [_mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@44);
        make.bottom.equalTo(@0);
    }];
}
- (UIImageView *)mainImageView{
    if (!_mainImageView) {
        UIImageView *view = [[UIImageView alloc]init];
        view.backgroundColor = [UIColor lightGrayColor];
        _mainImageView = view;
    }
    return _mainImageView;
}
- (UIButton *)backButton{
    if (!_backButton) {
        UIButton *sender = [UIButton buttonWithType:UIButtonTypeCustom];
        [sender setTitle:@" 返回" forState:UIControlStateNormal];
        [sender setTitleColor:[UIColorChange colorwithHexString:@"#20B097"] forState:UIControlStateNormal];
        [sender setImage:[UIImage imageNamed:@"back_color"] forState:UIControlStateNormal];
        sender.titleLabel.font = [UIFont systemFontOfSize:12];
        [sender addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        _backButton = sender;
    }
    return _backButton;
}
- (void)backClick:(UIButton *)sender{
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(APP_WIDTH, 0, MAINW, self.frame.size.height);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
#pragma mark - 得到试卷详情
- (void)getShiJuanDetailRequest{
   NSString *encoded = [self.path stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [_mainImageView sd_setImageWithURL:[NSURL URLWithString:encoded]];
    
}
@end
